package dao;

import java.util.ArrayList;
import java.util.HashMap;

import org.springframework.orm.ibatis.SqlMapClientTemplate;

import util.Utilities;
import dto.MemberDTO;
import dto.ProductDTO;
import dto.SaleListDTO;

public class SaleDAO {
	private SqlMapClientTemplate sqlMap;
	public SaleDAO(SqlMapClientTemplate sqlMap) {
		this.sqlMap = sqlMap;
	}
	public int selectSaleNo(){
		return (Integer) sqlMap.queryForObject("sale.selectSaleNo");
	}
	
	public void insertSaleSelf(SaleListDTO saleDTO){
		sqlMap.insert("sale.insertSale", saleDTO);
	}
	
	public ArrayList<SaleListDTO> selectSaleByMemId(String memId){
		return (ArrayList<SaleListDTO>) sqlMap.queryForList("sale.selectSaleByMemId", memId);
	}
	
	public void updateSaleByNo(SaleListDTO saleDTO){
		sqlMap.update("sale.updateSale",saleDTO);
	}
	
	public void updatePictureFileName(int saleNo) {
		sqlMap.update("sale.deleteFileName",saleNo);
	}
	
	public SaleListDTO selectSaleByNo(int saleNo) {
		return (SaleListDTO) sqlMap.queryForObject("sale.selectSaleBysaleNo",saleNo);
	}
	public void deleteSaleByNo(int saleNo) {
		sqlMap.delete("sale.deleteSale",saleNo);
	}
	
	public ArrayList<SaleListDTO> selectSaleListByPaging(int page){
		HashMap map = new HashMap();
		map.put("page", page);
		map.put("perPage", Utilities.CONTENT_PER_PAGE);
		return (ArrayList<SaleListDTO>) sqlMap.queryForList("sale.selectSaleListByPage",map);
	}
	
	public int selectSaleTotalContent(){
		return (Integer) sqlMap.queryForObject("sale.selectTotalContent");
	}
	
	public void updateMemberMileage(MemberDTO mdto){
		sqlMap.update("member.updateMemberMileage", mdto);
	}
	
	public ArrayList<ProductDTO> selectProductByProductName(String productName){
		return  (ArrayList<ProductDTO>) sqlMap.queryForList("product.selectProductByName",productName);
	}
	
	public ArrayList<ProductDTO> selectProductByPrice(int start, int end){
		HashMap map = new HashMap();
		map.put("start", start);
		map.put("end", end);
		return (ArrayList<ProductDTO>) sqlMap.queryForList("product.selectProductByPrice" ,map);
	}
	
	public ArrayList<ProductDTO> selectProductByCompany(String companyId){
		return  (ArrayList<ProductDTO>) sqlMap.queryForList("product.selectProductByCompanyId", companyId);
	}
	
	public ArrayList<ProductDTO> selectProductToSale(HashMap map){
		return (ArrayList<ProductDTO>)sqlMap.queryForList("product.selectProductToSale",map);
	}
	public ProductDTO selectProductByProductId(int productId) {
		return (ProductDTO) sqlMap.queryForObject("product.searchByProductId",productId);
	}
	
	
}
